package cn.zyzpp.service.resume.impl;

import cn.zyzpp.dao.InternshipDao;
import cn.zyzpp.entity.resume.Internship;
import cn.zyzpp.service.resume.InternshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Create by yster@foxmail.com 2018/5/21/021 22:46
 */
@Service
@CacheConfig(cacheNames = {"InternshipService"})
public class InternshipServiceImpl implements InternshipService {
    @Autowired
    private InternshipDao internshipDao;

    @Override
    @CacheEvict(allEntries = true)
    public void save(Internship internship, int uid) {
        internship.setUid(uid);
        internshipDao.save(internship);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void delect(int id) {
        internshipDao.deleteAllById(id);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void updataByUid(Internship internship) {
        Internship internship1 = internshipDao.findByUid(internship.getUid());
        internship1.updata(internship);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public List<Internship> queryAll(int uid) {
        return internshipDao.findAllByUid(uid);
    }
}
